package com.geekstudy.serialize;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.math.BigDecimal;

public final class DemoBigDecimalSerialize  extends JsonSerializer<Object> {


    @Override
    public void serialize(Object value, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
        if(value != null) {
            if(value instanceof BigDecimal) {
                BigDecimal bigDecimal = (BigDecimal)value;
                jsonGenerator.writeString(bigDecimal.toString());
            } else {
                jsonGenerator.writeString(value.toString());
            }
        } else {
            jsonGenerator.writeString("");
        }
    }



}
